Skip to content

Refactor tilt animation engine for performance and maintainability#157

Closed
Katotodan wants to merge 2 commits intomeshery-extensions:masterfrom
Katotodan:chore/animation
Closed

Refactor tilt animation engine for performance and maintainability#157
Katotodan wants to merge 2 commits intomeshery-extensions:masterfrom
Katotodan:chore/animation

Conversation

@Katotodan
Copy link
Copy Markdown
Contributor

@Katotodan Katotodan commented Mar 9, 2026

Notes for Reviewers

Summary

This PR refactors the tilt animation engine to improve performance, reduce layout recalculations, and simplify the architecture.

The goal is to make the animation logic more scalable and maintainable while preserving the existing visual behavior.

Key Improvements

Centralized State

Introduced a state object to manage:

  • pointer position
  • visible targets
  • cached bounding rectangles
  • animation frame scheduling
  • layout invalidation

This removes the need for multiple scattered variables.

Visibility-Based Updates

Added an IntersectionObserver to track visible elements.

Only elements currently in the viewport are processed during animation updates.

Cached Layout Measurements

Bounding rectangles are cached and only recalculated when necessary:

  • when elements enter the viewport
  • when a resize occurs
  • when scroll invalidates layout

This significantly reduces calls to getBoundingClientRect().

ResizeObserver Integration

ResizeObserver is used to detect element size changes and mark the layout as dirty only when needed.

Scroll Throttling

Scroll updates are throttled using requestAnimationFrame to avoid repeated layout invalidation.

Read / Write Separation

The animation engine now clearly separates:

  • Measurement phase (DOM reads)
  • Render phase (DOM writes)

This helps prevent layout thrashing and improves animation smoothness.

GPU Rendering Hint

Tilt elements now receive:
This hints the browser to optimize rendering for smoother animations.

Result

The refactor improves:

  • performance
  • scalability
  • maintainability
  • animation smoothness

while preserving the existing user-facing behavior.

Visual Changes

None intended.
The tilt and floating animations should behave the same as before.

Testing

Tested locally by:

  • moving the pointer across the hero section
  • verifying tilt effects on [data-tilt] elements
  • scrolling elements in and out of the viewport
  • resizing the window

Animations behave as expected.

Signed commits

  • Yes, I signed my commits.

Signed-off-by: DANIEL KATOTO <katotodan@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 9, 2026

PR Preview Action v1.6.3
Preview removed because the pull request was closed.
2026-04-28 14:29 UTC

@Bhumikagarggg
Copy link
Copy Markdown
Contributor

Bhumikagarggg commented Mar 22, 2026

@Katotodan Thank you for your contribution! Let's discuss this during the website call tomorrow at 5:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂

@Katotodan Katotodan closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Extensions] Refactor hero tilt animation engine for performance and maintainability

2 participants